#!/bin/env python
#-*- coding:utf-8 -*-
'''


@author: Admin
'''
import os 
import time
import datetime
import calendar
import re 
from datetime import date, timedelta

curr_dir = os.getcwd()
logs_dir = 'logs'
clean_file_list = []
class Clean_Logs(object):
    def __init__(self):
        pass             
    def get_curr_month_range(self, start_date=None):
        if start_date is None:
            start_date = date.today().replace(day=1)
            days_in_month = calendar.monthrange(start_date.year, start_date.month)
            end_date = start_date + timedelta(days=days_in_month[1])
        return (start_date, end_date)    
    
    def get_last_month_range(self, start_date=None):
        if start_date is None:
            start_date = (date.today() - timedelta(days=date.today().day)).replace(day=1)
            days_in_month = calendar.monthrange(start_date.year, start_date.month)
            end_date = start_date + timedelta(days=days_in_month[1])
        return (start_date, end_date)
    
    def get_clean_file(self):
        logs_dir = os.listdir(logs_dir)
        for clean_file_path in logs_dir:
            for clean_file in clean_file_path:
                pass
                
        return clean_file_list
    
    def clean_logs(self, file_path):
        os.remove(file_path)
    

       
        
        

    
if __name__ == '__main__':
#     last_month_day = datetime.date(datetime.date.today().year,datetime.date.today().month,1) - datetime.timedelta(days=1)
#     print "last_month_day: %s" % last_month_day
#     for day in range(1, last_month_day.day + 1):
#         print day
#     print datetime.datetime.today().year, (datetime.datetime.today().month + 1)
#     print calendar.monthrange(datetime.datetime.today().year, (datetime.datetime.today().month + 1))
#     first_day, last_day = get_last_month_range()
    cl = Clean_Logs()
    a_day = timedelta(days=1)
    first_day, last_day = cl.get_last_month_range()
    while first_day < last_day:
        print "first_day: %s" % first_day
        first_day += a_day
    clean_file_list = []
    p = r'\d+-\d+-\d+.Info\.*(\d+)?(\.)?log'
    p_reg = re.compile(p, re.IGNORECASE)
    print len(os.listdir('logs'))
    for file in os.listdir('logs'):
        if not p_reg.findall(file):
            clean_file_list.append(file)
    print clean_file_list
